<!DOCTYPE HTML>
<html lang="en" class="light" dir="ltr">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>字面量表达式 - The Rust Reference</title>


        <!-- Custom HTML head -->
        
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff">

        <link rel="icon" href="../favicon.svg">
        <link rel="shortcut icon" href="../favicon.png">
        <link rel="stylesheet" href="../css/variables.css">
        <link rel="stylesheet" href="../css/general.css">
        <link rel="stylesheet" href="../css/chrome.css">
        <link rel="stylesheet" href="../css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="../fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="../highlight.css">
        <link rel="stylesheet" href="../tomorrow-night.css">
        <link rel="stylesheet" href="../ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        <link rel="stylesheet" href="../theme/reference.css">

    </head>
    <body class="sidebar-visible no-js">
    <div id="body-container">
        <!-- Provide site root to javascript -->
        <script>
            var path_to_root = "../";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script>
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script>
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('light')
            html.classList.add(theme);
            var body = document.querySelector('body');
            body.classList.remove('no-js')
            body.classList.add('js');
        </script>

        <input type="checkbox" id="sidebar-toggle-anchor" class="hidden">

        <!-- Hide / unhide sidebar before it is displayed -->
        <script>
            var body = document.querySelector('body');
            var sidebar = null;
            var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            } else {
                sidebar = 'hidden';
            }
            sidebar_toggle.checked = sidebar === 'visible';
            body.classList.remove('sidebar-visible');
            body.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="../翻译说明.html">翻译说明</a></li><li class="chapter-item expanded affix "><a href="../introduction.html">介绍</a></li><li class="chapter-item expanded "><a href="../notation.html"><strong aria-hidden="true">1.</strong> 表义符</a></li><li class="chapter-item expanded "><a href="../lexical-structure.html"><strong aria-hidden="true">2.</strong> 词法结构</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../input-format.html"><strong aria-hidden="true">2.1.</strong> 输入格式</a></li><li class="chapter-item expanded "><a href="../keywords.html"><strong aria-hidden="true">2.2.</strong> 关键字</a></li><li class="chapter-item expanded "><a href="../identifiers.html"><strong aria-hidden="true">2.3.</strong> 标识符</a></li><li class="chapter-item expanded "><a href="../comments.html"><strong aria-hidden="true">2.4.</strong> 注释</a></li><li class="chapter-item expanded "><a href="../whitespace.html"><strong aria-hidden="true">2.5.</strong> 空白符</a></li><li class="chapter-item expanded "><a href="../tokens.html"><strong aria-hidden="true">2.6.</strong> token</a></li></ol></li><li class="chapter-item expanded "><a href="../macros.html"><strong aria-hidden="true">3.</strong> 宏</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../macros-by-example.html"><strong aria-hidden="true">3.1.</strong> 声明宏</a></li><li class="chapter-item expanded "><a href="../procedural-macros.html"><strong aria-hidden="true">3.2.</strong> 过程宏</a></li></ol></li><li class="chapter-item expanded "><a href="../crates-and-source-files.html"><strong aria-hidden="true">4.</strong> crate 和源文件</a></li><li class="chapter-item expanded "><a href="../conditional-compilation.html"><strong aria-hidden="true">5.</strong> 条件编译</a></li><li class="chapter-item expanded "><a href="../items.html"><strong aria-hidden="true">6.</strong> 程序项</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../items/modules.html"><strong aria-hidden="true">6.1.</strong> 模块</a></li><li class="chapter-item expanded "><a href="../items/extern-crates.html"><strong aria-hidden="true">6.2.</strong> 外部crate</a></li><li class="chapter-item expanded "><a href="../items/use-declarations.html"><strong aria-hidden="true">6.3.</strong> use声明</a></li><li class="chapter-item expanded "><a href="../items/functions.html"><strong aria-hidden="true">6.4.</strong> 函数</a></li><li class="chapter-item expanded "><a href="../items/type-aliases.html"><strong aria-hidden="true">6.5.</strong> 类型别名</a></li><li class="chapter-item expanded "><a href="../items/structs.html"><strong aria-hidden="true">6.6.</strong> 结构体</a></li><li class="chapter-item expanded "><a href="../items/enumerations.html"><strong aria-hidden="true">6.7.</strong> 枚举</a></li><li class="chapter-item expanded "><a href="../items/unions.html"><strong aria-hidden="true">6.8.</strong> 联合体</a></li><li class="chapter-item expanded "><a href="../items/constant-items.html"><strong aria-hidden="true">6.9.</strong> 常量项</a></li><li class="chapter-item expanded "><a href="../items/static-items.html"><strong aria-hidden="true">6.10.</strong> 静态项</a></li><li class="chapter-item expanded "><a href="../items/traits.html"><strong aria-hidden="true">6.11.</strong> trait</a></li><li class="chapter-item expanded "><a href="../items/implementations.html"><strong aria-hidden="true">6.12.</strong> 实现</a></li><li class="chapter-item expanded "><a href="../items/external-blocks.html"><strong aria-hidden="true">6.13.</strong> 外部块</a></li><li class="chapter-item expanded "><a href="../items/generics.html"><strong aria-hidden="true">6.14.</strong> 泛型参数</a></li><li class="chapter-item expanded "><a href="../items/associated-items.html"><strong aria-hidden="true">6.15.</strong> 关联程序项</a></li></ol></li><li class="chapter-item expanded "><a href="../attributes.html"><strong aria-hidden="true">7.</strong> 属性</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../attributes/testing.html"><strong aria-hidden="true">7.1.</strong> 测试</a></li><li class="chapter-item expanded "><a href="../attributes/derive.html"><strong aria-hidden="true">7.2.</strong> 派生</a></li><li class="chapter-item expanded "><a href="../attributes/diagnostics.html"><strong aria-hidden="true">7.3.</strong> 诊断</a></li><li class="chapter-item expanded "><a href="../attributes/codegen.html"><strong aria-hidden="true">7.4.</strong> 代码生成</a></li><li class="chapter-item expanded "><a href="../attributes/limits.html"><strong aria-hidden="true">7.5.</strong> 极限值设置</a></li><li class="chapter-item expanded "><a href="../attributes/type_system.html"><strong aria-hidden="true">7.6.</strong> 类型系统</a></li><li class="chapter-item expanded "><a href="../attributes/debugger.html"><strong aria-hidden="true">7.7.</strong> 调试器</a></li></ol></li><li class="chapter-item expanded "><a href="../statements-and-expressions.html"><strong aria-hidden="true">8.</strong> 语句和表达式</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../statements.html"><strong aria-hidden="true">8.1.</strong> 语句</a></li><li class="chapter-item expanded "><a href="../expressions.html"><strong aria-hidden="true">8.2.</strong> 表达式</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../expressions/literal-expr.html" class="active"><strong aria-hidden="true">8.2.1.</strong> 字面量表达式</a></li><li class="chapter-item expanded "><a href="../expressions/path-expr.html"><strong aria-hidden="true">8.2.2.</strong> 路径表达式</a></li><li class="chapter-item expanded "><a href="../expressions/block-expr.html"><strong aria-hidden="true">8.2.3.</strong> 块表达式</a></li><li class="chapter-item expanded "><a href="../expressions/operator-expr.html"><strong aria-hidden="true">8.2.4.</strong> 运算符表达式</a></li><li class="chapter-item expanded "><a href="../expressions/grouped-expr.html"><strong aria-hidden="true">8.2.5.</strong> 分组表达式</a></li><li class="chapter-item expanded "><a href="../expressions/array-expr.html"><strong aria-hidden="true">8.2.6.</strong> 数组和索引表达式</a></li><li class="chapter-item expanded "><a href="../expressions/tuple-expr.html"><strong aria-hidden="true">8.2.7.</strong> 元组和索引表达式</a></li><li class="chapter-item expanded "><a href="../expressions/struct-expr.html"><strong aria-hidden="true">8.2.8.</strong> 结构体表达式</a></li><li class="chapter-item expanded "><a href="../expressions/call-expr.html"><strong aria-hidden="true">8.2.9.</strong> 调用表达式</a></li><li class="chapter-item expanded "><a href="../expressions/method-call-expr.html"><strong aria-hidden="true">8.2.10.</strong> 方法调用表达式</a></li><li class="chapter-item expanded "><a href="../expressions/field-expr.html"><strong aria-hidden="true">8.2.11.</strong> 字段访问表达式</a></li><li class="chapter-item expanded "><a href="../expressions/closure-expr.html"><strong aria-hidden="true">8.2.12.</strong> 闭包表达式</a></li><li class="chapter-item expanded "><a href="../expressions/loop-expr.html"><strong aria-hidden="true">8.2.13.</strong> 循环表达式</a></li><li class="chapter-item expanded "><a href="../expressions/range-expr.html"><strong aria-hidden="true">8.2.14.</strong> 区间表达式</a></li><li class="chapter-item expanded "><a href="../expressions/if-expr.html"><strong aria-hidden="true">8.2.15.</strong> if 和 if let 表达式</a></li><li class="chapter-item expanded "><a href="../expressions/match-expr.html"><strong aria-hidden="true">8.2.16.</strong> 匹配表达式</a></li><li class="chapter-item expanded "><a href="../expressions/return-expr.html"><strong aria-hidden="true">8.2.17.</strong> 返回表达式</a></li><li class="chapter-item expanded "><a href="../expressions/await-expr.html"><strong aria-hidden="true">8.2.18.</strong> 等待(await)表达式</a></li><li class="chapter-item expanded "><a href="../expressions/underscore-expr.html"><strong aria-hidden="true">8.2.19.</strong> 下划线表达式</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="../patterns.html"><strong aria-hidden="true">9.</strong> 模式</a></li><li class="chapter-item expanded "><a href="../type-system.html"><strong aria-hidden="true">10.</strong> 类型系统</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../types.html"><strong aria-hidden="true">10.1.</strong> 类型</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../types/boolean.html"><strong aria-hidden="true">10.1.1.</strong> 布尔型</a></li><li class="chapter-item expanded "><a href="../types/numeric.html"><strong aria-hidden="true">10.1.2.</strong> 数字型</a></li><li class="chapter-item expanded "><a href="../types/textual.html"><strong aria-hidden="true">10.1.3.</strong> 字符型</a></li><li class="chapter-item expanded "><a href="../types/never.html"><strong aria-hidden="true">10.1.4.</strong> never类型</a></li><li class="chapter-item expanded "><a href="../types/tuple.html"><strong aria-hidden="true">10.1.5.</strong> 元组</a></li><li class="chapter-item expanded "><a href="../types/array.html"><strong aria-hidden="true">10.1.6.</strong> 数组</a></li><li class="chapter-item expanded "><a href="../types/slice.html"><strong aria-hidden="true">10.1.7.</strong> 切片</a></li><li class="chapter-item expanded "><a href="../types/struct.html"><strong aria-hidden="true">10.1.8.</strong> 结构体</a></li><li class="chapter-item expanded "><a href="../types/enum.html"><strong aria-hidden="true">10.1.9.</strong> 枚举</a></li><li class="chapter-item expanded "><a href="../types/union.html"><strong aria-hidden="true">10.1.10.</strong> 联合体</a></li><li class="chapter-item expanded "><a href="../types/function-item.html"><strong aria-hidden="true">10.1.11.</strong> 函数项类型</a></li><li class="chapter-item expanded "><a href="../types/closure.html"><strong aria-hidden="true">10.1.12.</strong> 闭包</a></li><li class="chapter-item expanded "><a href="../types/pointer.html"><strong aria-hidden="true">10.1.13.</strong> 指针型</a></li><li class="chapter-item expanded "><a href="../types/function-pointer.html"><strong aria-hidden="true">10.1.14.</strong> 函数指针</a></li><li class="chapter-item expanded "><a href="../types/trait-object.html"><strong aria-hidden="true">10.1.15.</strong> trait对象</a></li><li class="chapter-item expanded "><a href="../types/impl-trait.html"><strong aria-hidden="true">10.1.16.</strong> 实现trait</a></li><li class="chapter-item expanded "><a href="../types/parameters.html"><strong aria-hidden="true">10.1.17.</strong> 类型参数</a></li><li class="chapter-item expanded "><a href="../types/inferred.html"><strong aria-hidden="true">10.1.18.</strong> 可推断类型</a></li></ol></li><li class="chapter-item expanded "><a href="../dynamically-sized-types.html"><strong aria-hidden="true">10.2.</strong> 动态内存宽度类型(DST)</a></li><li class="chapter-item expanded "><a href="../type-layout.html"><strong aria-hidden="true">10.3.</strong> 类型布局 </a></li><li class="chapter-item expanded "><a href="../interior-mutability.html"><strong aria-hidden="true">10.4.</strong> 内部可变性</a></li><li class="chapter-item expanded "><a href="../subtyping.html"><strong aria-hidden="true">10.5.</strong> 子类型和型变</a></li><li class="chapter-item expanded "><a href="../trait-bounds.html"><strong aria-hidden="true">10.6.</strong> trait约束及其生存期约束</a></li><li class="chapter-item expanded "><a href="../type-coercions.html"><strong aria-hidden="true">10.7.</strong> 类型自动强转</a></li><li class="chapter-item expanded "><a href="../destructors.html"><strong aria-hidden="true">10.8.</strong> 析构函数</a></li><li class="chapter-item expanded "><a href="../lifetime-elision.html"><strong aria-hidden="true">10.9.</strong> 生存期省略</a></li></ol></li><li class="chapter-item expanded "><a href="../special-types-and-traits.html"><strong aria-hidden="true">11.</strong> 特殊类型和 trait</a></li><li class="chapter-item expanded "><a href="../names.html"><strong aria-hidden="true">12.</strong> 名称</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../names/namespaces.html"><strong aria-hidden="true">12.1.</strong> 命名空间</a></li><li class="chapter-item expanded "><a href="../names/scopes.html"><strong aria-hidden="true">12.2.</strong> 作用域</a></li><li class="chapter-item expanded "><a href="../names/preludes.html"><strong aria-hidden="true">12.3.</strong> 预导入包</a></li><li class="chapter-item expanded "><a href="../paths.html"><strong aria-hidden="true">12.4.</strong> 路径</a></li><li class="chapter-item expanded "><a href="../names/name-resolution.html"><strong aria-hidden="true">12.5.</strong> 名称解析</a></li><li class="chapter-item expanded "><a href="../visibility-and-privacy.html"><strong aria-hidden="true">12.6.</strong> 可见性与隐私权</a></li></ol></li><li class="chapter-item expanded "><a href="../memory-model.html"><strong aria-hidden="true">13.</strong> 内存模型</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../memory-allocation-and-lifetime.html"><strong aria-hidden="true">13.1.</strong> 内存分配和生存期</a></li><li class="chapter-item expanded "><a href="../variables.html"><strong aria-hidden="true">13.2.</strong> 变量</a></li></ol></li><li class="chapter-item expanded "><a href="../linkage.html"><strong aria-hidden="true">14.</strong> 链接</a></li><li class="chapter-item expanded "><a href="../inline-assembly.html"><strong aria-hidden="true">15.</strong> 内联汇编</a></li><li class="chapter-item expanded "><a href="../unsafety.html"><strong aria-hidden="true">16.</strong> 非安全性</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../unsafe-keyword.html"><strong aria-hidden="true">16.1.</strong> T关键字unsafe</a></li><li class="chapter-item expanded "><a href="../behavior-considered-undefined.html"><strong aria-hidden="true">16.2.</strong> 未定义行为</a></li><li class="chapter-item expanded "><a href="../behavior-not-considered-unsafe.html"><strong aria-hidden="true">16.3.</strong> 不被认为是非安全的行为</a></li></ol></li><li class="chapter-item expanded "><a href="../const_eval.html"><strong aria-hidden="true">17.</strong> 常量求值</a></li><li class="chapter-item expanded "><a href="../abi.html"><strong aria-hidden="true">18.</strong> ABI</a></li><li class="chapter-item expanded "><a href="../runtime.html"><strong aria-hidden="true">19.</strong> Rust运行时</a></li><li class="chapter-item expanded "><a href="../appendices.html"><strong aria-hidden="true">20.</strong> 附录</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="../macro-ambiguity.html"><strong aria-hidden="true">20.1.</strong> 宏规范</a></li><li class="chapter-item expanded "><a href="../influences.html"><strong aria-hidden="true">20.2.</strong> 影响来源</a></li><li class="chapter-item expanded "><a href="../glossary.html"><strong aria-hidden="true">20.3.</strong> 术语表</a></li><li class="chapter-item expanded "><a href="../本书术语翻译对照表.html"><strong aria-hidden="true">20.4.</strong> 本书术语翻译对照表</a></li></ol></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle">
                <div class="sidebar-resize-indicator"></div>
            </div>
        </nav>

        <!-- Track and set sidebar scroll position -->
        <script>
            var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
            sidebarScrollbox.addEventListener('click', function(e) {
                if (e.target.tagName === 'A') {
                    sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
                }
            }, { passive: true });
            var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
            sessionStorage.removeItem('sidebar-scroll');
            if (sidebarScrollTop) {
                // preserve sidebar scroll position when navigating via links within sidebar
                sidebarScrollbox.scrollTop = sidebarScrollTop;
            } else {
                // scroll sidebar to current active section when navigating via "next/previous chapter" buttons
                var activeSection = document.querySelector('#sidebar .active');
                if (activeSection) {
                    activeSection.scrollIntoView({ block: 'center' });
                }
            }
        </script>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky">
                    <div class="left-buttons">
                        <label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </label>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">The Rust Reference</h1>

                    <div class="right-buttons">
                        <a href="../print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>
                        <a href="https://github.com/rust-lang/reference/" title="Git repository" aria-label="Git repository">
                            <i id="git-repository-button" class="fa fa-github"></i>
                        </a>
                        <a href="https://github.com/rust-lang/reference/edit/master/src/expressions/literal-expr.md" title="Suggest an edit" aria-label="Suggest an edit">
                            <i id="git-edit-button" class="fa fa-edit"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script>
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="literal-expressions"><a class="header" href="#literal-expressions">Literal expressions</a></h1>
<h1 id="字面量表达式"><a class="header" href="#字面量表达式">字面量表达式</a></h1>
<blockquote>
<p><a href="https://github.com/rust-lang/reference/blob/master/src/expressions/literal-expr.md">literal-expr.md</a><br />
commit: 659915cc1169e13329186748e26ec1e5c6a92d4d <br />
本章译文最后维护日期：2024-04-06</p>
</blockquote>
<blockquote>
<p><strong><sup>词法</sup></strong><br />
<em>LiteralExpression</em> :<br />
      [CHAR_LITERAL]<br />
   | [STRING_LITERAL]<br />
   | [RAW_STRING_LITERAL]<br />
   | [BYTE_LITERAL]<br />
   | [BYTE_STRING_LITERAL]<br />
   | [RAW_BYTE_STRING_LITERAL]<br />
   | [C_STRING_LITERAL]<br />
   | [RAW_C_STRING_LITERAL]<br />
   | [INTEGER_LITERAL]<br />
   | [FLOAT_LITERAL]<br />
   | <code>true</code> | <code>false</code>&gt;</p>
</blockquote>
<p>字面表达式是由单一 token（而不是一组 token）组成的表达式，它立即和直接表示其表达式求值的值，而不是通过名称或其他求值规则来引用它。
它直接描述一个数字、字符、字符串或布尔值。</p>
<p>字面量是[常量表达式][constant expression]的一种形式，所以其求值（主要）在编译期。</p>
<p>前面描述的每种词法[字面量][literal tokens]形式都可以组成一个字面量表达式，比如关键字 <code>true</code> 和 <code>false</code> 也可以组成一个字面量表达式。</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>"hello";   // 字符串类型
'5';       // 字符类型
5;         // 整型
<span class="boring">}</span></code></pre></pre>
<p>在下面的描述中，token 的 <em>字符串表示</em> 是源自输入的字符序列，该字符序列会与<em>词法</em>语法片段中 token 的产生式进行模式匹配。</p>
<blockquote>
<p><strong>注意</strong>：此字符串表示从不包括紧跟着 <code>U+000A</code> (LF) 的字符 <code>U+000D</code> (CR)：这一对字符会先被转换为单个字符 <code>U+000A</code> (LF)。</p>
</blockquote>
<h2 id="escapes"><a class="header" href="#escapes">Escapes</a></h2>
<h2 id="转义"><a class="header" href="#转义">转义</a></h2>
<p>下面对文本字面表达式的描述使用了几种形式的 <em>转义</em>。</p>
<p>每种形式的转义的特点是：</p>
<ul>
<li><em>转义序列</em>: 总是以 <code>U+005C</code> (<code>\</code>) 开头的一段字符序列</li>
<li><em>转义值</em>: 单个字符或空的字符序列</li>
</ul>
<p>在以下关于转义的定义中：</p>
<ul>
<li><em>八进制数字</em> 是在 [<code>0</code>-<code>7</code>] 区间内的任何字符。</li>
<li><em>十六进制数字</em> 是在 [<code>0</code>-<code>9</code>]、[<code>a</code>-<code>f</code>] 或 [<code>A</code>-<code>F</code>] 这三个区间内的任何字符。</li>
</ul>
<h3 id="simple-escapes"><a class="header" href="#simple-escapes">Simple escapes</a></h3>
<h3 id="简单转义"><a class="header" href="#简单转义">简单转义</a></h3>
<p>下表第一列中出现的每个字符序列都是转义序列。</p>
<p>在每种情况下，转义值都是第二列中相应条目中给定的字符。</p>
<div class="table-wrapper"><table><thead><tr><th>转义序列</th><th>转义值</th></tr></thead><tbody>
<tr><td><code>\0</code></td><td>U+0000 (NUL)</td></tr>
<tr><td><code>\t</code></td><td>U+0009 (HT)</td></tr>
<tr><td><code>\n</code></td><td>U+000A (LF)</td></tr>
<tr><td><code>\r</code></td><td>U+000D (CR)</td></tr>
<tr><td><code>\"</code></td><td>U+0022 (双引号)</td></tr>
<tr><td><code>\'</code></td><td>U+0027 (单引号)</td></tr>
<tr><td><code>\\</code></td><td>U+005C (反斜线)</td></tr>
</tbody></table>
</div>
<h3 id="8-bit-escapes"><a class="header" href="#8-bit-escapes">8-bit escapes</a></h3>
<h3 id="8bit字符值转义"><a class="header" href="#8bit字符值转义">8bit字符值转义</a></h3>
<p>这种转义序列由 <code>\x</code> 后跟两个十六进制数字组成。</p>
<p>转义值是一个字符，其 [Unicode标量值][Unicode scalar value]是将转义序列中的最后两个字符解释为十六进制整数的结果，就好像对这两个字符执行了以16为基数的[<code>u8::from_str_radix</code>]操作。</p>
<blockquote>
<p><strong>注意</strong>: 作为结果的转义值因此具有在 [<code>u8</code>][numeric types] 数值区间内的 [Unicode标量值][Unicode scalar value]。</p>
</blockquote>
<h3 id="7-bit-escapes"><a class="header" href="#7-bit-escapes">7-bit escapes</a></h3>
<h3 id="7bit字符值转义"><a class="header" href="#7bit字符值转义">7bit字符值转义</a></h3>
<p>转义序列由 <code>\x</code> 后跟一个八进制数字和一个十六进制数字组成。
转义值是一个字符，其[Unicode标量值][Unicode scalar value]是将转义序列中的最后两个字符解释为十六进制整数的结果，就好像对这两个字符执行了以16为基数的[<code>u8::from_str_radix</code>]操作。</p>
<h3 id="unicode-escapes"><a class="header" href="#unicode-escapes">Unicode escapes</a></h3>
<h3 id="unicode字符值转义"><a class="header" href="#unicode字符值转义">Unicode字符值转义</a></h3>
<p>转义序列由 <code>\u{</code> 后跟一系列字符组成，每个字符都是十六进制数字或 <code>_</code> ，在后跟一个 <code>}</code>。
转义值是一个字符，其[Unicode标量值][Unicode scalar value]是将转义序列中包含的十六进制数字解释为十六进制整数的结果，就好像对这一段字符执行了以16为基数的[<code>u32::from_str_radix</code>]操作。</p>
<blockquote>
<p><strong>注意</strong>: [CHAR_LITERAL] token 或 [STRING_LITERA] token 的词法定义形式确保存在这样的字符。</p>
</blockquote>
<h3 id="string-continuation-escapes"><a class="header" href="#string-continuation-escapes">String continuation escapes</a></h3>
<h3 id="字符串接续符转义"><a class="header" href="#字符串接续符转义">字符串接续符转义</a></h3>
<p>转义序列由 <code>\</code> 后面紧跟着 <code>U+000A</code> (LF)，以及在下一个非空白符之前的所有后面的空白符组成。
为此，空白符被限定为 <code>U+0009</code> (HT)、<code>U+000A</code> (LF)、<code>U+000D</code> (CR) 和 <code>U+0020</code> (空格符)。</p>
<p>转义值是一个空的字符序列。</p>
<blockquote>
<p><strong>注意</strong>: 这种转义形式的效果是字符串延续跳过后面的空白符（包括额外的换行符）。
因此下面 <code>a</code>、 <code>b</code> 和 <code>c</code> 是相等的:</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let a = "foobar";
let b = "foo\
         bar";
let c = "foo\

     bar";

assert_eq!(a, b);
assert_eq!(b, c);
<span class="boring">}</span></code></pre></pre>
<p>跳过额外的换行符（如上面示例中的变量c 所示）可能会造成潜在混乱和意外。
这种行为将来可能会进行调整。
在做出决定之前，建议避免使用带有多个换行符接续符。
请参阅 <a href="https://github.com/rust-lang/reference/pull/1042">this issue</a>，以了解更多信息。</p>
</blockquote>
<h2 id="character-literal-expressions"><a class="header" href="#character-literal-expressions">Character literal expressions</a></h2>
<h2 id="字符字面量表达式"><a class="header" href="#字符字面量表达式">字符字面量表达式</a></h2>
<p>字符字面量表达式由单一一个[字符字面量][CHAR_LITERAL]token 组成。</p>
<p>此表达式的类型是 rust的源语类型 [<code>char</code>][textual types]。</p>
<p>此类token 不能带有后缀。</p>
<p>此类token 的 <em>字面内容</em> 是在此token的字符串表示中第一个 <code>U+0027</code> (<code>'</code>) 之后，最后一个 <code>U+0027</code> (<code>'</code>) 之前的字符序列。</p>
<p>此类字面量表达式的 <em>所表示字符</em> 源自字面内容，具体有如下规则：</p>
<ul>
<li>如果字面内容是以下转义序列形式之一，则所表示的字符是转义序列的转义值：
<ul>
<li>[简单转义][Simple escapes]</li>
<li>[7bit转义][7-bit escapes]</li>
<li>[Unicode转义][Unicode escapes]</li>
</ul>
</li>
<li>否则，所表示的字符是构成字面内容的单个字符。</li>
</ul>
<p>表达式的值是与所表示的字符的[Unicode标量值][Unicode scalar value]相对应的 [<code>char</code>][text types]类型。</p>
<blockquote>
<p><strong>注意</strong>: [CHAR_LITERAL] token 的词法定义形式确保会产生单一字符。</p>
</blockquote>
<p>字符字面量表达式示例：</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>'R';                               // R
'\'';                              // '
'\x52';                            // R
'\u{00E6}';                        // 拉丁文小写字母æ (U+00E6)
<span class="boring">}</span></code></pre></pre>
<h2 id="string-literal-expressions"><a class="header" href="#string-literal-expressions">String literal expressions</a></h2>
<h2 id="字符串字面量表达式"><a class="header" href="#字符串字面量表达式">字符串字面量表达式</a></h2>
<p>字符串字面量表达式由单一一个[字符串字面量][STRING_LITERAL]token 或[原生字符串字面量][RAW_STRING_LITERAL]token 组成。</p>
<p>此类表达式的类型是对原语类型 [<code>str</code>][text types] 的共享引用（带有 <code>static</code>生存期)。
也就是说，类型是 <code>&amp;'static str</code>。</p>
<p>此类token 不能带有后缀。</p>
<p>此类token 的 <em>字面内容</em> 是此token 的字符串表示中第一个 <code>U+0022</code> (<code>"</code>) 之后和最后一个 <code>U+0022</code> (<code>"</code>) 之前的字符序列。</p>
<p>此字面量表达式的 <em>所表示字符串</em> 源自于字符序列的字面内容，具体有如下规则：</p>
<ul>
<li>
<p>如果 token 是[STRING_LTERAL]词法所限定的，则字面内容中出现的以下任何形式的转义序列都将被转义序列的转义值替换。</p>
<ul>
<li>[简单转义][Simple escapes]</li>
<li>[7bit转义][7-bit escapes]</li>
<li>[Unicode转义][Unicode escapes]</li>
<li>[字符串接续符转义][String continuation escapes]</li>
</ul>
<p>这些转义替换按从左到右的顺序进行的。
例如，token <code>"\\x41"</code> 被转换为字符 <code>\</code> <code>x</code> <code>4</code> <code>1</code>。</p>
</li>
<li>
<p>如果 token 是[RAW_STRING_LITERAL]词法所限定的，则所表示的字符串等同于字面内容。</p>
</li>
</ul>
<p>表达式的值是对静态分配的 [<code>str</code>][text types]的引用，该引用包含所表示字符串的 UTF-8编码形式。</p>
<p>字符串字面量表达式示例：</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>"foo"; r"foo";                     // foo
"\"foo\""; r#""foo""#;             // "foo"

"foo #\"# bar";
r##"foo #"# bar"##;                // foo #"# bar

"\x52"; "R"; r"R";                 // R
"\\x52"; r"\x52";                  // \x52
<span class="boring">}</span></code></pre></pre>
<h2 id="byte-literal-expressions"><a class="header" href="#byte-literal-expressions">Byte literal expressions</a></h2>
<h2 id="字节字面量表达式"><a class="header" href="#字节字面量表达式">字节字面量表达式</a></h2>
<p>字节字面量表达式由单一一个[字节字面量][BYTE_LITERAL]token 组成。</p>
<p>此表达式的类型是 rust的源语类型 [<code>u8</code>][numeric types]。</p>
<p>此类token 不能带有后缀。</p>
<p>此类token 的 <em>字面内容</em> 是此token 的字符串表示中第一个 <code>U+0027</code> (<code>'</code>) 之后和最后一个 <code>U+0027</code> (<code>'</code>) 之前的字符序列。</p>
<p>此字面量表达式的 <em>所表示字符</em> 源自于字符的字面内容，具体有如下规则：</p>
<ul>
<li>
<p>如果字面内容是以下转义序列形式之一，则表示的字符是转义序列的转义值：</p>
<ul>
<li>[简单转义][Simple escapes]</li>
<li>[8bit转义][8-bit escapes]</li>
</ul>
</li>
<li>
<p>否则，所表示的字符是构成字面内容的单个字符。</p>
</li>
</ul>
<p>此类表达式的值是所表示的字符的[Unicode标量值][Unicode scalar value]。</p>
<blockquote>
<p><strong>注意</strong>: [BYTE_LTERAL] token 的词法定义形式确保这些规则始终能生成一个 Unicode标量值在 [<code>u8</code>][numeric types] 数值区间内的单个字符。</p>
</blockquote>
<p>字节字面量表达式的示例：</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>b'R';                              // 82
b'\'';                             // 39
b'\x52';                           // 82
b'\xA0';                           // 160
<span class="boring">}</span></code></pre></pre>
<h2 id="byte-string-literal-expressions"><a class="header" href="#byte-string-literal-expressions">Byte string literal expressions</a></h2>
<h2 id="字节串字面量表达式"><a class="header" href="#字节串字面量表达式">字节串字面量表达式</a></h2>
<p>字节串字面量表达式由单一一个[字节串字面量][BYTE_STRING_LITERAL]token 或[原生字节串字面量][RAW_BYTE_STRING_LITERAL]token 组成。</p>
<p>此类表达式的类型是对元素类型为 [<code>u8</code>][numeric-types]的数组的共享引用（带有 <code>static</code>生存期）。
也就是说，类型是 <code>&amp;'static [u8; N]</code>，其中 <code>N</code> 是下文描述的所表示的字符串的字节数。</p>
<p>此类token 不能带有后缀。</p>
<p>此类token 的 <em>字面内容</em> 是此token 的字符串表示中第一个 <code>U+0022</code> (<code>"</code>) 之后和最后一个 <code>U+0022</code> (<code>"</code>) 之前的字符序列。</p>
<p>此字面量表达式的 <em>所表示字符串</em> 源自于字符序列的字面内容，具体有如下规则：</p>
<ul>
<li>
<p>如果 token 是[BYTE_STRING_LITERAL]词法所限定的，则字面内容中出现的以下任何形式的每个转义序列都将替换为转义序列的转义值。</p>
<ul>
<li>[简单转义][Simple escapes]</li>
<li>[8bit转义][8-bit escapes]</li>
<li>[字符串接续符转义][String continuation escapes]</li>
</ul>
<p>这些转义替换按从左到右的顺序进行的。
例如，token <code>b"\\x41"</code> 被转换为字符 <code>\</code> <code>x</code> <code>4</code> <code>1</code>。</p>
</li>
<li>
<p>如果 token 是[RAW_BYTE_STRING_LITERAL]词法所限定的，则所表示的字符串等同于字面内容。</p>
</li>
</ul>
<p>表达式的值是对静态分配的数组的引用，该数组包含所表示字符串中字符的[Unicode标量值][Unicode scalar values]，顺序相同。</p>
<blockquote>
<p><strong>注意</strong>: [BYTE_STRING_LITERAL] 和 [RAW_BYTE_STRING_LITERAL] 的词法定义形式确保这些规则生成数组元素值始终在 [<code>u8</code>][numeric types] 数值区间内。</p>
</blockquote>
<p>字节串字面量表达式的示例:</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>b"foo"; br"foo";                     // foo
b"\"foo\""; br#""foo""#;             // "foo"

b"foo #\"# bar";
br##"foo #"# bar"##;                 // foo #"# bar

b"\x52"; b"R"; br"R";                // R
b"\\x52"; br"\x52";                  // \x52
<span class="boring">}</span></code></pre></pre>
<h2 id="c-string-literal-expressions"><a class="header" href="#c-string-literal-expressions">C string literal expressions</a></h2>
<h2 id="c语言风格的字符串字面量表达式"><a class="header" href="#c语言风格的字符串字面量表达式">C语言风格的字符串字面量表达式</a></h2>
<p>C语言风格的字符串字面量表达式由单一一个[C语言风格的字符串字面量][C_STRING_LITERAL] 或 [原生C语言风格的字符串字面量][RAW_C_STRING_LITERAL] token 组成。</p>
<p>此类表达式的类型是对标准库[CStr]类型的共享引用（带有 <code>static</code>生存期）。
也就是说，类型是 <code>&amp;'static core::ffi::CStr</code>。</p>
<p>此类token 不能带有后缀。</p>
<p>此类token 的 <em>字面内容</em> 是此token 的字符串表示中第一个 <code>U+0022</code> (<code>"</code>) 之后和最后一个 <code>U+0022</code> (<code>"</code>) 之前的字符序列。</p>
<p>此类字面量表达式的 <em>所表示字节序</em> 源自于字节序列的字面内容，具体有如下规则：</p>
<ul>
<li>
<p>如果 token 是[C_STRING_LITERAL]词法所限定的，则字面内容被视为一系列内容项（下面有罗列），每个内容项要么是除 <code>\</code> 之外的单个 Unicode字符，要么是[转义][escape]。
内容项序列会被转换为字节序列，具体规则如下所示：</p>
<ul>
<li>每个 Unicode字符都有 UTF-8表示形式。</li>
<li>每个[简单转义][simple escape]都会被转义为其转义值的[Unicode标量值][Unicode scalar value]。</li>
<li>每个[8bit转义][8-bit escape]都会被转义为一个包含其转义值的[Unicode标量值][Unicode scalar value]的单个字节。</li>
<li>每个[Unicode转义][unicode escape]都会被转义为其转义值的 UTF-8表示形式。</li>
<li>每个[字符串接续符转义][string continuation escape]都不会被转义为任何字节。</li>
</ul>
</li>
<li>
<p>如果 token [RAW_C_STRING_LITERAL] 词法所限定的，则表示的字节是字面内容的 UTF-8编码。</p>
</li>
</ul>
<blockquote>
<p><strong>注意</strong>: [C_STRING_LITERAL] 和 [RAW_C_STRING_LITERAL]的词法定义形式确保所表示的字节序不会包含 null字节。</p>
</blockquote>
<p>The expression’s value is a reference to a statically allocated [CStr] whose array of bytes contains the represented bytes followed by a null byte.
该表达式的值是对静态分配的 [CStr] 的引用，其字节数组就包含了这个后跟一个 null字节的所表示字节序。</p>
<p>C语言风格的字符串字面量表达式示例:</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>c"foo"; cr"foo";                     // foo
c"\"foo\""; cr#""foo""#;             // "foo"

c"foo #\"# bar";
cr##"foo #"# bar"##;                 // foo #"# bar

c"\x52"; c"R"; cr"R";                // R
c"\\x52"; cr"\x52";                  // \x52

c"æ";                                // 拉丁文小写字母æ (U+00E6)
c"\u{00E6}";                         // 拉丁文小写字母æ (U+00E6)
c"\xC3\xA6";                         // 拉丁文小写字母æ (U+00E6)

c"\xE6".to_bytes();                  // [230]
c"\u{00E6}".to_bytes();              // [195, 166]
<span class="boring">}</span></code></pre></pre>
<h2 id="integer-literal-expressions"><a class="header" href="#integer-literal-expressions">Integer literal expressions</a></h2>
<h2 id="整型字面量表达式"><a class="header" href="#整型字面量表达式">整型字面量表达式</a></h2>
<p>整型字面量表达式由单一一个[整型字面量][INTEGER_LITERAL]token 组成。</p>
<p>如果这种 token 带有[后缀][suffix]，那这个后缀的名字必须是[原生整型][numeric types]中的一个：<code>u8</code>, <code>i8</code>, <code>u16</code>, <code>i16</code>, <code>u32</code>, <code>i32</code>, <code>u64</code>, <code>i64</code>, <code>u128</code>, <code>i128</code>, <code>usize</code> 或 <code>isize</code>，同时此后缀名也是此表达式的类型。</p>
<p>如果此 token 没有后缀，此表达式的类型将由下面的类型推断规则来确定:</p>
<ul>
<li>
<p>如果整型可以从周围的程序上下文中<em>唯一地</em>确定，则表达式具有该类型。</p>
</li>
<li>
<p>如果程序上下文对类型的约束比较宽松，则默认为有符号32位整数 <code>i32</code>。</p>
</li>
<li>
<p>如果程序上下文对类型的约束过度，则被认为是一个静态类型错误。</p>
</li>
</ul>
<p>整型字面量表达式的示例：</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>123;                               // type i32
123i32;                            // type i32
123u32;                            // type u32
123_u32;                           // type u32
let a: u64 = 123;                  // type u64

0xff;                              // type i32
0xff_u8;                           // type u8

0o70;                              // type i32
0o70_i16;                          // type i16

0b1111_1111_1001_0000;             // type i32
0b1111_1111_1001_0000i64;          // type i64

0usize;                            // type usize
<span class="boring">}</span></code></pre></pre>
<p>而表达式的值由 token 的字符串表示形式来确定，规则如下：</p>
<ul>
<li>
<p>通过检查字符串的前两个字符来选择整型的进制数，如下所示：</p>
<ul>
<li><code>0b</code> 表示进制数为2</li>
<li><code>0o</code> 表示进制数为8</li>
<li><code>0x</code> 表示进制数为16</li>
<li>其他表示进制数为10。</li>
</ul>
</li>
<li>
<p>如果进制数不是10，则从字符串中删除前两个字符。</p>
</li>
<li>
<p>字符串的后缀都会被删除。</p>
</li>
<li>
<p>字符串里的下划线都会被删除。</p>
</li>
<li>
<p>字符串被转换为 <code>u128</code>类型的值时，比如使用 [<code>u128::from_str_radix</code>] 时选的进制数标记。
如果该值不能被表示为 <code>u128</code>，将在编译时报错。</p>
</li>
<li>
<p><code>u128</code>类型的值通过[数值转换][numeric cast]转换为表达式的类型。</p>
</li>
</ul>
<blockquote>
<p><strong>注意</strong>: 如果字面量的值不适合表达式的类型，则会对最终强制转换的结果做截断操作。
<code>rustc</code> 包含一个名为 <code>overflowing_literals</code> 的 [lint检查][lint check]， 默认生效级别为 <code>deny</code>， 这意味着这种情况发生是此表达式会被编译器拒绝。</p>
</blockquote>
<blockquote>
<p><strong>注意</strong>： <code>-1i8</code> 这样的表达式是对 <code>1i8</code> 这个字面量表达式的[取负操作][negation operator]，不是一个单一的整型字面量表达式。
请参阅[Overflow]，了解有关表示有符号类型的最大负值的说明。</p>
</blockquote>
<h2 id="floating-point-literal-expressions"><a class="header" href="#floating-point-literal-expressions">Floating-point literal expressions</a></h2>
<h2 id="浮点型字面量表达式"><a class="header" href="#浮点型字面量表达式">浮点型字面量表达式</a></h2>
<p>浮点型字面量表达式由下面两种形式：[浮点型字面量][FLOAT_LITERAL]token 组成。</p>
<ul>
<li>由单一的[浮点型字面量][FLOAT_LITERAL]token 组成</li>
<li>由单一的没有后缀和基数指示符的[整型字面量][INTEGER_LITERAL]token 组成</li>
</ul>
<p>如果这种 token 带有[后缀][suffix]，那这个后缀的名字必须是[原生浮点型][floating-point types]中的一个：<code>f32</code> 或 <code>f64</code>，同时此后缀名也是此表达式的类型。</p>
<p>如果这种 token 没有后缀，此表达式的类型将由下面的类型推断规则来确定:</p>
<ul>
<li>
<p>如果浮点型可以从周围的程序上下文中<em>唯一地</em>确定，则表达式具有该类型。</p>
</li>
<li>
<p>如果程序上下文对类型的约束比较宽松，则默认为 <code>f64</code>。</p>
</li>
<li>
<p>如果程序上下文对类型的约束过度，则被认为是一个静态类型错误。</p>
</li>
</ul>
<p>浮点型字面量表达式的示例：</p>
<pre><pre class="playground"><code class="language-rust edition2021"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>123.0f64;        // type f64
0.1f64;          // type f64
0.1f32;          // type f32
12E+99_f64;      // type f64
5f32;            // type f32
let x: f64 = 2.; // type f64
<span class="boring">}</span></code></pre></pre>
<p>而表达式的值由 token 的字符串表示形式来确定，规则如下：</p>
<ul>
<li>
<p>字符串的后缀都会被删除。</p>
</li>
<li>
<p>字符串中的下划线都会被删除。</p>
</li>
<li>
<p>字符串被转换为这类表达式类型时，如同直接调用 [<code>f32::from_str</code>] 或 [<code>f64::from_str</code>]。</p>
</li>
</ul>
<blockquote>
<p><strong>注意</strong>: <code>-1.0</code> 这样的表达式是对 <code>1.0</code> 这个字面量表达式的[取负操作][negation operator]，不是一个单一的浮点型字面量表达式。</p>
</blockquote>
<blockquote>
<p><strong>注意</strong>: <code>inf</code> 和 <code>NaN</code> 不是字面量token。
[<code>f32::INFINITY</code>], [<code>f64::INFINITY</code>], [<code>f32::NAN</code>] 和 [<code>f64::NAN</code>] 这些常量可被用来替代字面量表达式。</p>
</blockquote>
<blockquote>
<p>在 <code>rustc</code> 里，一个足够大的字面量被计算为无穷时将会触发一个叫做 <code>overflowing_literals</code> 的 lint检查。</p>
</blockquote>
<h2 id="boolean-literal-expressions"><a class="header" href="#boolean-literal-expressions">Boolean literal expressions</a></h2>
<h2 id="布尔型字面量表达式"><a class="header" href="#布尔型字面量表达式">布尔型字面量表达式</a></h2>
<p>布尔型字面量表达式由关键字 <code>true</code> 或 <code>false</code> 中的一个组成。</p>
<p>此类表达式的类型是原生[布尔型][boolean type]，并且它的值为：</p>
<ul>
<li>如果关键字是 <code>true</code>，那么值为 true</li>
<li>如果关键字是 <code>false</code>，那么值为 false
[Escape]: #escapes
[Simple escape]: #simple-escapes
[Simple escapes]: #simple-escapes
[8-bit escape]: #8-bit-escapes
[8-bit escapes]: #8-bit-escapes
[7-bit escape]: #7-bit-escapes
[7-bit escapes]: #7-bit-escapes
[Unicode escape]: #unicode-escapes
[Unicode escapes]: #unicode-escapes
[String continuation escape]: #string-continuation-escapes
[String continuation escapes]: #string-continuation-escapes
[boolean type]: ../types/boolean.md
[constant expression]: ../const_eval.md#constant-expressions
[CStr]: https://doc.rust-lang.org/core/ffi/struct.CStr.html
[floating-point types]: ../types/numeric.md#floating-point-types
[lint check]: ../attributes/diagnostics.md#lint-check-attributes
[literal tokens]: ../tokens.md#literals
[numeric cast]: operator-expr.md#numeric-cast
[numeric types]: ../types/numeric.md
[suffix]: ../tokens.md#suffixes
[negation operator]: operator-expr.md#negation-operators
[overflow]: operator-expr.md#overflow
[textual types]: ../types/textual.md
[Unicode scalar value]: http://www.unicode.org/glossary/#unicode_scalar_value
[Unicode scalar values]: http://www.unicode.org/glossary/#unicode_scalar_value
[<code>f32::from_str</code>]: https://doc.rust-lang.org/core/primitive.f32.html#method.from_str
[<code>f32::INFINITY</code>]: https://doc.rust-lang.org/core/primitive.f32.md#associatedconstant.INFINITY
[<code>f32::NAN</code>]: https://doc.rust-lang.org/core/primitive.f32.md#associatedconstant.NAN
[<code>f64::from_str</code>]: https://doc.rust-lang.org/core/primitive.f64.md#method.from_str
[<code>f64::INFINITY</code>]: https://doc.rust-lang.org/core/primitive.f64.md#associatedconstant.INFINITY
[<code>f64::NAN</code>]: https://doc.rust-lang.org/core/primitive.f64.md#associatedconstant.NAN
[<code>u8::from_str_radix</code>]: https://doc.rust-lang.org/core/primitive.u8.md#method.from_str_radix
[<code>u32::from_str_radix</code>]: https://doc.rust-lang.org/core/primitive.u32.md#method.from_str_radix
[<code>u128::from_str_radix</code>]: https://doc.rust-lang.org/core/primitive.u128.md#method.from_str_radix
[CHAR_LITERAL]: ../tokens.md#character-literals
[STRING_LITERAL]: ../tokens.md#string-literals
[RAW_STRING_LITERAL]: ../tokens.md#raw-string-literals
[BYTE_LITERAL]: ../tokens.md#byte-literals
[BYTE_STRING_LITERAL]: ../tokens.md#byte-string-literals
[RAW_BYTE_STRING_LITERAL]: ../tokens.md#raw-byte-string-literals
[C_STRING_LITERAL]: ../tokens.md#c-string-literals
[RAW_C_STRING_LITERAL]: ../tokens.md#raw-c-string-literals
[INTEGER_LITERAL]: ../tokens.md#integer-literals
[FLOAT_LITERAL]: ../tokens.md#floating-point-literals
[asm]: ../inline-assembly.md#asm
[asm.abi-clobbers]: ../inline-assembly.md#asm.abi-clobbers
[asm.abi-clobbers.explicit-have-precedence]: ../inline-assembly.md#asm.abi-clobbers.explicit-have-precedence
[asm.abi-clobbers.intro]: ../inline-assembly.md#asm.abi-clobbers.intro
[asm.abi-clobbers.many]: ../inline-assembly.md#asm.abi-clobbers.many
[asm.abi-clobbers.must-specify]: ../inline-assembly.md#asm.abi-clobbers.must-specify
[asm.abi-clobbers.supported-abis]: ../inline-assembly.md#asm.abi-clobbers.supported-abis
[asm.directives]: ../inline-assembly.md#asm.directives
[asm.directives.stateful]: ../inline-assembly.md#asm.directives.stateful
[asm.directives.subset-supported]: ../inline-assembly.md#asm.directives.subset-supported
[asm.directives.supported-directives]: ../inline-assembly.md#asm.directives.supported-directives
[asm.example]: ../inline-assembly.md#asm.example
[asm.intro]: ../inline-assembly.md#asm.intro
[asm.operand-type]: ../inline-assembly.md#asm.operand-type
[asm.operand-type.global_asm-restriction]: ../inline-assembly.md#asm.operand-type.global_asm-restriction
[asm.operand-type.left-to-right]: ../inline-assembly.md#asm.operand-type.left-to-right
[asm.operand-type.supported-operands]: ../inline-assembly.md#asm.operand-type.supported-operands
[asm.operand-type.supported-operands.in]: ../inline-assembly.md#asm.operand-type.supported-operands.in
[asm.operand-type.supported-operands.inlateout]: ../inline-assembly.md#asm.operand-type.supported-operands.inlateout
[asm.operand-type.supported-operands.inout]: ../inline-assembly.md#asm.operand-type.supported-operands.inout
[asm.operand-type.supported-operands.inout-arrow]: ../inline-assembly.md#asm.operand-type.supported-operands.inout-arrow
[asm.operand-type.supported-operands.lateout]: ../inline-assembly.md#asm.operand-type.supported-operands.lateout
[asm.operand-type.supported-operands.out]: ../inline-assembly.md#asm.operand-type.supported-operands.out
[asm.operand-type.supported-operands.sym]: ../inline-assembly.md#asm.operand-type.supported-operands.sym
[asm.options]: ../inline-assembly.md#asm.options
[asm.options.checks]: ../inline-assembly.md#asm.options.checks
[asm.options.checks.mutually-exclusive]: ../inline-assembly.md#asm.options.checks.mutually-exclusive
[asm.options.checks.noreturn]: ../inline-assembly.md#asm.options.checks.noreturn
[asm.options.checks.pure]: ../inline-assembly.md#asm.options.checks.pure
[asm.options.global_asm-restriction]: ../inline-assembly.md#asm.options.global_asm-restriction
[asm.options.supported-options]: ../inline-assembly.md#asm.options.supported-options
[asm.options.supported-options.att_syntax]: ../inline-assembly.md#asm.options.supported-options.att_syntax
[asm.options.supported-options.nomem]: ../inline-assembly.md#asm.options.supported-options.nomem
[asm.options.supported-options.noreturn]: ../inline-assembly.md#asm.options.supported-options.noreturn
[asm.options.supported-options.nostack]: ../inline-assembly.md#asm.options.supported-options.nostack
[asm.options.supported-options.preserves_flags]: ../inline-assembly.md#asm.options.supported-options.preserves_flags
[asm.options.supported-options.pure]: ../inline-assembly.md#asm.options.supported-options.pure
[asm.options.supported-options.raw]: ../inline-assembly.md#asm.options.supported-options.raw
[asm.options.supported-options.readonly]: ../inline-assembly.md#asm.options.supported-options.readonly
[asm.register-names]: ../inline-assembly.md#asm.register-names
[asm.register-names.fp-bp-reserved]: ../inline-assembly.md#asm.register-names.fp-bp-reserved
[asm.register-names.not-for-io]: ../inline-assembly.md#asm.register-names.not-for-io
[asm.register-names.supported-register-aliases]: ../inline-assembly.md#asm.register-names.supported-register-aliases
[asm.register-operands]: ../inline-assembly.md#asm.register-operands
[asm.register-operands.allowed-types]: ../inline-assembly.md#asm.register-operands.allowed-types
[asm.register-operands.equivalence-to-base-register]: ../inline-assembly.md#asm.register-operands.equivalence-to-base-register
[asm.register-operands.error-overlapping]: ../inline-assembly.md#asm.register-operands.error-overlapping
[asm.register-operands.error-two-operands]: ../inline-assembly.md#asm.register-operands.error-two-operands
[asm.register-operands.register-or-class]: ../inline-assembly.md#asm.register-operands.register-or-class
[asm.register-operands.separate-input-output]: ../inline-assembly.md#asm.register-operands.separate-input-output
[asm.register-operands.smaller-value]: ../inline-assembly.md#asm.register-operands.smaller-value
[asm.register-operands.supported-register-classes]: ../inline-assembly.md#asm.register-operands.supported-register-classes
[asm.register-operands.value-type-constraints]: ../inline-assembly.md#asm.register-operands.value-type-constraints
[asm.rules]: ../inline-assembly.md#asm.rules
[asm.rules.black-box]: ../inline-assembly.md#asm.rules.black-box
[asm.rules.intro]: ../inline-assembly.md#asm.rules.intro
[asm.rules.mem-same-as-ffi]: ../inline-assembly.md#asm.rules.mem-same-as-ffi
[asm.rules.noreturn]: ../inline-assembly.md#asm.rules.noreturn
[asm.rules.not-exactly-once]: ../inline-assembly.md#asm.rules.not-exactly-once
[asm.rules.not-successive]: ../inline-assembly.md#asm.rules.not-successive
[asm.rules.only-on-exit]: ../inline-assembly.md#asm.rules.only-on-exit
[asm.rules.preserved-registers]: ../inline-assembly.md#asm.rules.preserved-registers
[asm.rules.preserves_flags]: ../inline-assembly.md#asm.rules.preserves_flags
[asm.rules.pure]: ../inline-assembly.md#asm.rules.pure
[asm.rules.reg-not-input]: ../inline-assembly.md#asm.rules.reg-not-input
[asm.rules.reg-not-output]: ../inline-assembly.md#asm.rules.reg-not-output
[asm.rules.stack-below-sp]: ../inline-assembly.md#asm.rules.stack-below-sp
[asm.rules.unwind]: ../inline-assembly.md#asm.rules.unwind
[asm.rules.x86-df]: ../inline-assembly.md#asm.rules.x86-df
[asm.rules.x86-prefix-restriction]: ../inline-assembly.md#asm.rules.x86-prefix-restriction
[asm.rules.x86-x87]: ../inline-assembly.md#asm.rules.x86-x87
[asm.scope]: ../inline-assembly.md#asm.scope
[asm.scope.asm]: ../inline-assembly.md#asm.scope.asm
[asm.scope.global_asm]: ../inline-assembly.md#asm.scope.global_asm
[asm.scope.intro]: ../inline-assembly.md#asm.scope.intro
[asm.stable-targets]: ../inline-assembly.md#asm.stable-targets
[asm.syntax]: ../inline-assembly.md#asm.syntax
[asm.target-specific-directives]: ../inline-assembly.md#asm.target-specific-directives
[asm.target-specific-directives.arm-32-bit]: ../inline-assembly.md#asm.target-specific-directives.arm-32-bit
[asm.target-specific-directives.dwarf-unwinding]: ../inline-assembly.md#asm.target-specific-directives.dwarf-unwinding
[asm.target-specific-directives.structured-exception-handling]: ../inline-assembly.md#asm.target-specific-directives.structured-exception-handling
[asm.target-specific-directives.x86]: ../inline-assembly.md#asm.target-specific-directives.x86
[asm.template-modifiers]: ../inline-assembly.md#asm.template-modifiers
[asm.template-modifiers.intro]: ../inline-assembly.md#asm.template-modifiers.intro
[asm.template-modifiers.only-one]: ../inline-assembly.md#asm.template-modifiers.only-one
[asm.template-modifiers.smaller-value]: ../inline-assembly.md#asm.template-modifiers.smaller-value
[asm.template-modifiers.supported-modifiers]: ../inline-assembly.md#asm.template-modifiers.supported-modifiers
[asm.ts-args]: ../inline-assembly.md#asm.ts-args
[asm.ts-args.at-least-once]: ../inline-assembly.md#asm.ts-args.at-least-once
[asm.ts-args.before-other-args]: ../inline-assembly.md#asm.ts-args.before-other-args
[asm.ts-args.llvm-syntax]: ../inline-assembly.md#asm.ts-args.llvm-syntax
[asm.ts-args.no-implicit]: ../inline-assembly.md#asm.ts-args.no-implicit
[asm.ts-args.one-or-more]: ../inline-assembly.md#asm.ts-args.one-or-more
[asm.ts-args.opaque]: ../inline-assembly.md#asm.ts-args.opaque
[asm.ts-args.order]: ../inline-assembly.md#asm.ts-args.order
[asm.ts-args.positional-first]: ../inline-assembly.md#asm.ts-args.positional-first
[asm.ts-args.register-operands]: ../inline-assembly.md#asm.ts-args.register-operands
[asm.ts-args.syntax]: ../inline-assembly.md#asm.ts-args.syntax
[asm.validity]: ../inline-assembly.md#asm.validity
[asm.validity.necessary-but-not-sufficient]: ../inline-assembly.md#asm.validity.necessary-but-not-sufficient
[asm.validity.non-exhaustive]: ../inline-assembly.md#asm.validity.non-exhaustive</li>
</ul>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="../expressions.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>

                            <a rel="next prefetch" href="../expressions/path-expr.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="../expressions.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>

                    <a rel="next prefetch" href="../expressions/path-expr.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>




        <script>
            window.playground_copyable = true;
        </script>


        <script src="../elasticlunr.min.js"></script>
        <script src="../mark.min.js"></script>
        <script src="../searcher.js"></script>

        <script src="../clipboard.min.js"></script>
        <script src="../highlight.js"></script>
        <script src="../book.js"></script>

        <!-- Custom JS scripts -->


    </div>
    </body>
</html>
